import { rdsRequest, getRdsUrl} from './rdsServices';

const loaded = { current: false };
// 销项税
let taxRateItems = [];

// 进项税
let payTaxRateItems = [];

// 营业税
let saleTaxRateItems = [];

// 消费税
let consTaxRateItems = [];


const initTaxRate = async () => {
    const rdsUrl = getRdsUrl()

    if (loaded.current) {
        loaded.current = true;
        return;
    }
    const taxRateResult = await rdsRequest(rdsUrl.bcApi, 'Rds公共服务', 'GetAllTaxRate', '');
    if (!taxRateResult.HasException) {
        taxRateResult.map(x => {
            taxRateItems = taxRateResult
                .filter(item => item.c_tax_type === '2')
                .map(item => ({
                    value: item.c_tax_rate + '',
                    text: item.c_name
                }));

            payTaxRateItems = taxRateResult
                .filter(item => item.c_tax_type === '1')
                .map(item => ({
                    value: item.c_tax_rate,
                    text: item.c_name
                }));

            saleTaxRateItems = taxRateResult
                .filter(item => item.c_tax_type === '3')
                .map(item => ({
                    value: item.c_tax_rate + '',
                    text: item.c_name
                }));

            consTaxRateItems = taxRateResult
                .filter(item => item.c_tax_type === '4')
                .map(item => ({
                    value: item.c_tax_rate + '',
                    text: item.c_name
                }));

        });
    }
}



export {
    initTaxRate,
    taxRateItems,
    payTaxRateItems,
    saleTaxRateItems,
    consTaxRateItems
}